<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/10/11
 * Time: 11:13
 */
namespace app\models;

use think\Model;

/**
 * Class CateModel
 * @package app\models
 */
class CateModel extends Model
{
    protected $table = 'mt_cate';

    /**
     * 订单列表 分页
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $order
     * @return array
     * @throws \think\exception\DbException
     */
    public static function pageLists($where = [], $page = 1, $limit = 5, $order = 'id desc')
    {
        if ($where) {
            $result = self::where($where)->order($order)->paginate($limit, false, ['page' => $page]);
        } else {
            $result = self::order($order)->paginate($limit, false, ['page' => $page]);
        }
        if (!$result->total()) {
            return ['code' => 0, 'msg' => "ok", 'count' => 0, 'data' => []];
        }
        foreach ($result as $key => $value) {
            if($value['is_cate'] == 2){
                $result[$key]['cate_name'] = "<a style='color: #0000cc'>"."┝" . $value['cate_name'] . "</a>";
            }else if($value['is_cate'] == 3){
                $result[$key]['cate_name'] = "<a style='color: #009900'>" ."┝"."┝". $value['cate_name'] . "</a>";
            }else{
                $result[$key]['cate_name'] = "<a style='color: red'>" . $value['cate_name'] . "</a>";
            }
        }
        $result = $result->toArray();
        return ['code' => 0, 'msg' => "ok", 'count' => $result['total'], 'data' => $result['data']];
    }
}